<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>选择地址</title>

	</head>
	<body>
		<iframe style="width: 100vw;height: 100vh;" id="iframe" frameborder="0"></iframe>
		<!-- uni 的 SDK -->
		<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js">
		</script>
		<script>
			window._AMapSecurityConfig = {
				securityJsCode: 'e3b273297ee54ca76ef8b67cb8e4bd89',
			}
		</script>
		<script src="https://webapi.amap.com/maps?v=1.4.15&key=800dc6f37725820e6c2b5b7fccce5457"></script>
		<script type="text/javascript">
			function getQueryVariable(variable) {
				let query = window.location.search.substring(1);
				let vars = query.split("&");
				for (let i = 0; i < vars.length; i++) {
					let pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return (false);
			}
			const locations = getQueryVariable('location')
			const arr = locations.split(',')
			var iframe = document.getElementById('iframe');
			let url =
				`https://m.amap.com/picker/?keywords=写字楼,小区,学校&zoom=15&center=${arr[0]},${arr[1]}&radius=1000&total=20&key=800dc6f37725820e6c2b5b7fccce5457&jscode=e3b273297ee54ca76ef8b67cb8e4bd89`
			iframe.src = url
			console.log(url);

			(function() {
				document.getElementById('iframe').onload = function() {
					iframe.contentWindow.postMessage('hello', 'https://m.amap.com/picker/');
				};
				window.addEventListener("message", function(e) {
					// alert('您选择了:' + e.data.name + ',' + e.data.location)
					console.log(JSON.stringify(e.data));
					iframe.style.display = 'none'
					uni.postMessage({
						data: {
							action: e.data
						}
					});

				}, false);
			}())
		</script>
	</body>
</html>
